package cn.com.guage.dtm.stat.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.com.guage.dtm.common.annotation.Log;
import cn.com.guage.dtm.common.enums.BusinessType;
import cn.com.guage.dtm.stat.domain.StatDataCheckDetail;
import cn.com.guage.dtm.stat.service.IStatDataCheckDetailService;
import cn.com.guage.dtm.verify.domain.VerifyFieldRuleManage;
import cn.com.guage.dtm.common.core.controller.BaseController;
import cn.com.guage.dtm.common.core.domain.AjaxResult;
import cn.com.guage.dtm.common.utils.poi.ExcelUtil;
import cn.com.guage.dtm.common.core.page.TableDataInfo;

/**
 * 数据检核分析详情Controller
 * 
 * @author ruoyi
 * @date 2021-07-22
 */
@Controller
@RequestMapping("/stat/detail")
public class StatDataCheckDetailController extends BaseController
{
    private String prefix = "stat/detail";

    @Autowired
    private IStatDataCheckDetailService statDataCheckDetailService;

    @RequiresPermissions("stat:detail:view")
    @GetMapping()
    public String detail()
    {
        return prefix + "/detail";
    }

    /**
     * 查询数据检核分析详情列表
     */
    @RequiresPermissions("stat:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StatDataCheckDetail statDataCheckDetail)
    {
        startPage();
        List<StatDataCheckDetail> list = statDataCheckDetailService.selectStatDataCheckDetailList(statDataCheckDetail);
        return getDataTable(list);
    }

    /**
     * 导出数据检核分析详情列表
     */
    @RequiresPermissions("stat:detail:export")
    @Log(title = "数据检核分析详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StatDataCheckDetail statDataCheckDetail)
    {
        List<StatDataCheckDetail> list = statDataCheckDetailService.selectStatDataCheckDetailList(statDataCheckDetail);
        ExcelUtil<StatDataCheckDetail> util = new ExcelUtil<StatDataCheckDetail>(StatDataCheckDetail.class);
        return util.exportExcel(list, "数据检核分析详情数据");
    }

    /**
     * 新增数据检核分析详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数据检核分析详情
     */
    @RequiresPermissions("stat:detail:add")
    @Log(title = "数据检核分析详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StatDataCheckDetail statDataCheckDetail)
    {
        return toAjax(statDataCheckDetailService.insertStatDataCheckDetail(statDataCheckDetail));
    }

    /**
     * 修改数据检核分析详情
     */
    @GetMapping("/edit/{checkDetailId}")
    public String edit(@PathVariable("checkDetailId") Long checkDetailId, ModelMap mmap)
    {
        StatDataCheckDetail statDataCheckDetail = statDataCheckDetailService.selectStatDataCheckDetailById(checkDetailId);
        mmap.put("statDataCheckDetail", statDataCheckDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据检核分析详情
     */
    @RequiresPermissions("stat:detail:edit")
    @Log(title = "数据检核分析详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StatDataCheckDetail statDataCheckDetail)
    {
        return toAjax(statDataCheckDetailService.updateStatDataCheckDetail(statDataCheckDetail));
    }

    /**
     * 删除数据检核分析详情
     */
    @RequiresPermissions("stat:detail:remove")
    @Log(title = "数据检核分析详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(statDataCheckDetailService.deleteStatDataCheckDetailByIds(ids));
    }
    
    @PostMapping("/showStatDataCheckDetByCheckResultId")
  	@ResponseBody
  	public TableDataInfo showStatDataCheckDetByCheckResultId(StatDataCheckDetail statDataCheckDetail) {
    	StatDataCheckDetail queryParams = new StatDataCheckDetail();
  		queryParams.setCheckDetailId(statDataCheckDetail.getCheckDetailId());
  		startPage();
  		List<StatDataCheckDetail> list = statDataCheckDetailService.selectStatDataCheckDetailList(statDataCheckDetail);
  		return getDataTable(list);
  	}
}
